package com.zbs.framework.swagger.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义拦截器继承HandlerInterceptorAdapter 类
 */
@Slf4j
public class SwaggerInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        response.setHeader("Access-Control-Expose-Headers","Content-disposition");
        return true;
    }

}

//需要将拦截器加载到WebMvcConfigurerAdapter
@Configuration
class SwaggerWebMvcConfig implements WebMvcConfigurer {


    @Bean
    public SwaggerInterceptor swaggerInterceptor() {
        return new SwaggerInterceptor();
    }



    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(swaggerInterceptor());
    }

}

